package org.jeecg.modules.wlhy.company.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.modules.wlhy.company.entity.HyCompanyConfig;
import org.jeecg.modules.wlhy.company.mapper.HyCompanyConfigMapper;
import org.jeecg.modules.wlhy.company.service.IHyCompanyConfigService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: hy_company_config
 * @Author: jeecg-boot
 * @Date:   2021-07-01
 * @Version: V1.0
 */
@Service
@Slf4j
public class HyCompanyConfigServiceImpl extends ServiceImpl<HyCompanyConfigMapper, HyCompanyConfig> implements IHyCompanyConfigService {

    @Override
    @Cacheable(unless="#result == null", cacheNames= CacheConstant.CACHE_COMPANY_CONFIG, key="#p0")
    public HyCompanyConfig getByCompanyId(String companyId){
        QueryWrapper<HyCompanyConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company_id", companyId);
        HyCompanyConfig companyConfig = this.getOne(queryWrapper);
        return companyConfig;
    }
    
    @Override
    @CacheEvict(cacheNames=CacheConstant.CACHE_COMPANY_CONFIG, key="#companyConfig.companyId")
    public boolean edit(HyCompanyConfig companyConfig) {
        return this.updateById(companyConfig);
    }
}
